﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using findSerialPorts;
using System.Windows.Forms.DataVisualization.Charting;
using UART_PORTS;   // 用于调用串口缓冲区
using System.Threading;  // 多线程操作


namespace USB_CANDemo
{
    public partial class FrmMain : Form
    {
        #region 变量区域
        int signNum = 0;//定时器标记
        int sleepTime = 1000;//单位毫秒，响应时间

        #endregion

        static ComRecv_Class CR = new ComRecv_Class();
        static ComRecv_Class DisplayData = new ComRecv_Class();
        UInt32 CountValue = 0;
        byte[] Data = new byte[8];
        byte[] Data1 = new byte[8];

        public Queue<double> dataQueue = new Queue<double>(1000);
        public int curValue = 0;
        public int num = 5;//每次删除增加几个点

        public FrmMain()
        {
            InitializeComponent();
        }

        private void btn_SerialPortOpen_Click(object sender, EventArgs e)
        {
            Button btn_SerialPortOperate = (Button)sender;
            switch (btn_SerialPortOperate.Tag.ToString())
            {
                case "Open/Close":  // 打开/关闭串口
                    switch (btn_SerialPortOpen.Text)
                    {
                        case "打开串口":
                            try
                            {
                                string ComPortName = null;   // 我总感觉下面的总可以优化
                                { // 找串口号
                                    if (cmb_SerialPortIndex.Text[4] == ' ')  // COMn 形式
                                        ComPortName = cmb_SerialPortIndex.Text.Substring(0, 4);  // 表示从0开始，获取4个字符！
                                    else if (cmb_SerialPortIndex.Text[5] == ' ')  // COMnn 形式
                                        ComPortName = cmb_SerialPortIndex.Text.Substring(0, 5);
                                    else if (cmb_SerialPortIndex.Text[6] == ' ')  // COMnnn 形式
                                        ComPortName = cmb_SerialPortIndex.Text.Substring(0, 6);
                                    else if (cmb_SerialPortIndex.Text[7] == ' ')  // COMnnnn 形式
                                        ComPortName = cmb_SerialPortIndex.Text.Substring(0, 7);
                                }
                                serialPort1.PortName = ComPortName;
                                serialPort1.Open();
                                btn_SerialPortOpen.Text = "关闭串口";
                                cmb_SerialPortIndex.Enabled = false;
                                btn_SerialPortRefresh.Enabled = false;
                                lablel_SerialPortStatus.Text = "串口状态:已打开";
                            }
                            catch
                            {
                                MessageBox.Show("错误001:串口打开失败,请检查", "提示");
                            }
                            break;
                        case "关闭串口":
                            try
                            {
                                serialPort1.Close();
                                btn_SerialPortOpen.Text = "打开串口";
                                cmb_SerialPortIndex.Enabled = true;
                                btn_SerialPortRefresh.Enabled = true;
                                lablel_SerialPortStatus.Text = "串口状态:已关闭";
                            }
                            catch
                            {
                                MessageBox.Show("错误002:串口关闭失败,请检查", "提示");
                            }
                            break;
                        default: break;
                    }
                    break;
                case "Fresh":  // 刷新串口
                    SerialPortFresh();
                    break;
                default:
                    break;
            }
        }

        private void btn_SerialPortRefresh_Click(object sender, EventArgs e)
        {
            Button btn_SerialPortOperate = (Button)sender;
            switch (btn_SerialPortOperate.Tag.ToString())
            {
                case "Open/Close":  // 打开/关闭串口
                    switch (btn_SerialPortOpen.Text)
                    {
                        case "打开串口":
                            try
                            {
                                string ComPortName = null;   // 我总感觉下面的总可以优化
                                { // 找串口号
                                    if (cmb_SerialPortIndex.Text[4] == ' ')  // COMn 形式
                                        ComPortName = cmb_SerialPortIndex.Text.Substring(0, 4);  // 表示从0开始，获取4个字符！
                                    else if (cmb_SerialPortIndex.Text[5] == ' ')  // COMnn 形式
                                        ComPortName = cmb_SerialPortIndex.Text.Substring(0, 5);
                                    else if (cmb_SerialPortIndex.Text[6] == ' ')  // COMnnn 形式
                                        ComPortName = cmb_SerialPortIndex.Text.Substring(0, 6);
                                    else if (cmb_SerialPortIndex.Text[7] == ' ')  // COMnnnn 形式
                                        ComPortName = cmb_SerialPortIndex.Text.Substring(0, 7);
                                }
                                serialPort1.PortName = ComPortName;
                                serialPort1.Open();
                                btn_SerialPortOpen.Text = "关闭串口";
                                cmb_SerialPortIndex.Enabled = false;
                                btn_SerialPortRefresh.Enabled = false;
                                lablel_SerialPortStatus.Text = "串口状态:已打开";
                            }
                            catch
                            {
                                MessageBox.Show("错误001:串口打开失败,请检查", "提示");
                            }
                            break;
                        case "关闭串口":
                            try
                            {
                                serialPort1.Close();
                                btn_SerialPortOpen.Text = "打开串口";
                                cmb_SerialPortIndex.Enabled = true;
                                btn_SerialPortRefresh.Enabled = true;
                                lablel_SerialPortStatus.Text = "串口状态:已关闭";
                            }
                            catch
                            {
                                MessageBox.Show("错误002:串口关闭失败,请检查", "提示");
                            }
                            break;
                        default: break;
                    }
                    break;
                case "Fresh":  // 刷新串口
                    SerialPortFresh();
                    break;
                default:
                    break;
            }
        }

        public void SerialPortFresh()  // 刷新串口函数
        {
            cmb_SerialPortIndex.Items.Clear();
            cmb_SerialPortIndex.Text = string.Empty;
            string[] ports = Win32api_findSerialPorts.MulGetHardwareInfo(Win32api_findSerialPorts.HardwareEnum.Win32_PnPEntity, "Name"); // 使用WPI接口
            if (ports != null)
            {
                string[] rebuildPorts = new string[ports.Length];
                for (byte i = 0; i < ports.Length; i++)  // 下面的我也感觉到也可以优化
                {
                    for (byte j = 0; j < ports[i].Length; j++)
                    {
                        if ((ports[i][j] == '(')
                            && ports[i][j + 1] == 'C'
                            && (ports[i][j + 2] == 'O')
                            && ports[i][j + 3] == 'M'
                            )
                        {
                            if (ports[i][j + 5] == ')') // (COMn) 形式 
                            {
                                rebuildPorts[i] = "COM" + ports[i][j + 4] + " " + ports[i].Substring(0, j - 1);
                            }
                            else if (ports[i][j + 6] == ')') // (COMnn) 形式 
                            {
                                rebuildPorts[i] = "COM" + ports[i][j + 4] + ports[i][j + 5] + " " + ports[i].Substring(0, j - 1);
                            }
                            else if (ports[i][j + 7] == ')') // (COMnnn) 形式 
                            {
                                rebuildPorts[i] = "COM" + ports[i][j + 4] + +ports[i][j + 5] + ports[i][j + 6] + " " + ports[i].Substring(0, j - 1);
                            }
                            else if (ports[i][j + 8] == ')') // (COMnnnn) 形式 
                            {
                                rebuildPorts[i] = "COM" + ports[i][j + 4] + ports[i][j + 5] + ports[i][j + 5] + ports[i][j + 7] + " " + ports[i].Substring(0, j - 1);
                            }
                        }
                    }
                }
                cmb_SerialPortIndex.Items.AddRange(rebuildPorts);
                cmb_SerialPortIndex.SelectedIndex = cmb_SerialPortIndex.Items.Count > 0 ? 0 : -1;
            }
            else  // 几乎不会出现这种错误
            {
                MessageBox.Show("寻找COM口出错！");
                cmb_SerialPortIndex.Text = null;
            }
        }

        /****************下面的函数：为了实现串口可以根据USB事件来检测更新串口*******************/
        public const int WM_DEVICECHANGE = 0x0219;//WM_DeviceChange
        public enum WM_DEVICECHANGE_WPPARAMS
        {
            DBT_DEVICEARRIVAL = 0x8000,//DeviceArray
            DBT_DEVICEREMOVECOMPLETE = 0x8004,//DeviceMoveComplete
        };
        protected override void WndProc(ref Message m)
        {
            try
            {
                if (m.Msg == WM_DEVICECHANGE)
                {
                    switch ((WM_DEVICECHANGE_WPPARAMS)(m.WParam.ToInt32()))
                    {
                        case WM_DEVICECHANGE_WPPARAMS.DBT_DEVICEARRIVAL:
                            //  SerialPortFresh();
                            tmr_StrartRefreshCom.Enabled = Enabled;  // 根据发现，如果直接使用上面的操作的方式，会出现报错。所以用单次定时器处理。
                            break;
                        case WM_DEVICECHANGE_WPPARAMS.DBT_DEVICEREMOVECOMPLETE: //卸载
                            //  SerialPortFresh();
                            tmr_StrartRefreshCom.Enabled = Enabled;
                            break;
                        default:
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            base.WndProc(ref m);
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            //this.chart1.ChartAreas.Clear();
            //ChartArea chartArea1 = new ChartArea("C1");
            //this.chart1.ChartAreas.Add(chartArea1);
            ////定义存储和显示点的容器
            //this.chart1.Series.Clear();
            //Series series1 = new Series("S1");
            ////series1.ChartArea = "C1";
            //this.chart1.Series.Add(series1);
            ////设置图表显示样式
            //this.chart1.ChartAreas[0].AxisY.Minimum = 0;
            //this.chart1.ChartAreas[0].AxisY.Maximum = 100;
            //this.chart1.ChartAreas[0].AxisX.Interval = 5;
            //this.chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver;
            //this.chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver;
            ////设置标题
            //this.chart1.Titles.Clear();
            //this.chart1.Titles.Add("S01");
            //this.chart1.Titles[0].Text = "转速比值显示";
            //this.chart1.Titles[0].ForeColor = Color.RoyalBlue;
            //this.chart1.Titles[0].Font = new System.Drawing.Font("Microsoft Sans Serif", 12F);
            ////设置图表显示样式
            //this.chart1.Series[0].Color = Color.Red;
            //    this.chart1.Titles[0].Text = string.Format("转速{0}显示", "比值");
            //    this.chart1.Series[0].ChartType = SeriesChartType.Line;
            //this.chart1.Series[0].Points.Clear();

            tmr_StrartRefreshCom.Enabled = true;
            {
                Control.CheckForIllegalCrossThreadCalls = false;
            }
        }

        private void tmr_StrartRefreshCom_Tick(object sender, EventArgs e)
        {
            SerialPortFresh();
            tmr_StrartRefreshCom.Enabled = false;
        }


        private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            int n = serialPort1.BytesToRead;
            if (CR.pWrite + n > CR.MaxLength)
            {
                serialPort1.Read(CR.ComRecvBuf, CR.pWrite, CR.MaxLength - CR.pWrite);
                serialPort1.Read(CR.ComRecvBuf, 0, CR.pWrite + n - CR.MaxLength);
            }
            else
            {
                serialPort1.Read(CR.ComRecvBuf, CR.pWrite, n);
            }
            CR.pWrite = (UInt16)(CR.pWrite + n);
            CR.pWrite %= CR.MaxLength;
            //if ((((CR.pWrite + CR.MaxLength) - CR.pRead) % CR.MaxLength) >= CR.MinLen)
            ComProcess();
            //
        }
        public byte GetSumForCommand(byte[] Array)  // 专用求和函数
        {
            byte Sum = 0;
            for (byte temp = 0; temp <= 27; temp++)
            {
                Sum = (byte)(Sum + Array[temp]);
            }
            return Sum;
        }
        void ComProcess()
        {
            byte[] dataBuf = new byte[CR.MinLen];  // 定义临时数组
            if ((((CR.pWrite + CR.MaxLength) - CR.pRead) % CR.MaxLength) >= CR.MinLen)  // 当长度一定后开始处理
                do
                {
                    for (byte i = 0; i < CR.MinLen; i++)
                    {
                        dataBuf[i] = CR.ComRecvBuf[(CR.pRead + i) % CR.MaxLength];
                    }
                    //测试
                    //StringBuilder sb1 = new StringBuilder();
                    //sb1.Insert(sb1.Length, "接收：");
                    //foreach (byte i in dataBuf)
                    //{
                    //    sb1.Insert(sb1.Length, Convert.ToString(i, 16));
                    //    sb1.Insert(sb1.Length, " ");
                    //}
                    //sb1.Insert(sb1.Length, "\n");
                    //textBox3.AppendText(sb1.ToString());

                    //解析测试(显示）
                    LightStatusTest(dataBuf);  //灯态解析
                    Light81Test(dataBuf);       //亮故障检测
                    Light82Test(dataBuf);       //灭故障检测
                    Light83Test(dataBuf);       //电流解析
                    Light84Test(dataBuf);       //电压解析

                    //故障检测程序
                    // LightStatusAnay(dataBuf);

                    if ((dataBuf[0] == 0xAA) && (dataBuf[1] == 0x55) && (dataBuf[CR.MinLen - 1] == 0x88))
                    {
                        if (GetSumForCommand(dataBuf) == dataBuf[28])  // 为了提升性能，这个和检验功能去掉
                        {
                            switch (dataBuf[2])
                            {
                                case 1:   // 根据协议来，暂时不做解析！
                                    UInt32 BaduRate = (UInt32)((dataBuf[10] << 16) + (dataBuf[11] << 8) + (dataBuf[12]));
                                    lb_BaudRate.Text = BaduRate.ToString();
                                    break;
                                case 2:   // 这个报文只有接收成功计数
                                    CountValue = (UInt32)((dataBuf[3] << 24) + (dataBuf[4] << 16) + (dataBuf[5] << 8) + dataBuf[6]);
                                    lb_receiveValue.Text = CountValue.ToString();
                                    break;
                                case 3:   // 这个为接收的CAN报文
                                    // 先把有用信息提取出来
                                    UInt32 RIR = (UInt32)((dataBuf[3] << 24) + (dataBuf[4] << 16) + (dataBuf[5] << 8) + dataBuf[6]);
                                    UInt32 RDTR = (UInt32)((dataBuf[7] << 24) + (dataBuf[8] << 16) + (dataBuf[9] << 8) + dataBuf[10]);
                                    UInt32 RDHR = (UInt32)((dataBuf[11] << 24) + (dataBuf[12] << 16) + (dataBuf[13] << 8) + dataBuf[14]);
                                    UInt32 RDLR = (UInt32)((dataBuf[15] << 24) + (dataBuf[16] << 16) + (dataBuf[17] << 8) + dataBuf[18]);
                                    // 然后寄存器手册来操作！这里只做几个简单的演示！
                                    {
                                        if ((RIR & 0x6) == 0)  // 表示为标准帧，数据帧
                                        {
                                            if ((RDTR & 0x0F) == 0x08)  //表示数据长度为8位
                                            {

                                                //RIR
                                                Data1[0] = (byte)(RIR);
                                                Data1[1] = (byte)(RIR >> 8);
                                                Data1[2] = (byte)(RIR >> 16);
                                                Data1[3] = (byte)(RIR >> 24);
                                                //RDTR
                                                Data1[4] = (byte)(RDTR);
                                                Data1[5] = (byte)(RDTR >> 8);
                                                Data1[6] = (byte)(RDTR >> 16);
                                                Data1[7] = (byte)(RDTR >> 24);

                                                //RDLR
                                                Data[0] = (byte)(RDLR);         //0xbb
                                                Data[1] = (byte)(RDLR >> 8);    //命令字：0x80-灯态,0x81-故障该亮不亮,0x82-故障该灭不灭,0x83-电流，0x84-电压
                                                Data[2] = (byte)(RDLR >> 16);   //阶段顺序号
                                                Data[3] = (byte)(RDLR >> 24);   //剩余秒数

                                                //RDHR
                                                Data[4] = (byte)(RDHR);         //左、直、右、人；
                                                Data[5] = (byte)(RDHR >> 8);
                                                Data[6] = (byte)(RDHR >> 16);
                                                Data[7] = (byte)(RDHR >> 24);

                                                try
                                                {
                                                    textBox1.AppendText("接收"
                                                        + "RIR: "
                                                        + Convert.ToString(Data1[0], 16) + " "
                                                        + Convert.ToString(Data1[1], 16) + " "
                                                        + Convert.ToString(Data1[2], 16) + " "
                                                        + Convert.ToString(Data1[3], 16) + " "
                                                        + "RDTR: "
                                                        + Convert.ToString(Data1[4], 16) + " "
                                                        + Convert.ToString(Data1[5], 16) + " "
                                                        + Convert.ToString(Data1[6], 16) + " "
                                                        + Convert.ToString(Data1[7], 16) + " "
                                                        + "RDLR: "
                                                        + Convert.ToString(Data[0], 16) + " "
                                                        + Convert.ToString(Data[1], 16) + " "
                                                        + Convert.ToString(Data[2], 16) + " "
                                                        + Convert.ToString(Data[3], 16) + " "
                                                        + "RDHR: "
                                                        + Convert.ToString(Data[4], 16) + " "
                                                        + Convert.ToString(Data[5], 16) + " "
                                                        + Convert.ToString(Data[6], 16) + " "
                                                        + Convert.ToString(Data[7], 16) + " "
                                                        + "\r\n");
                                                    textBox1.AppendText("--\r\n");
                                                }
                                                catch
                                                {

                                                }

                                            }
                                        }
                                    }

                                    break;
                                default:
                                    break;
                            }
                            CR.pRead = (UInt16)(CR.pRead + CR.MinLen);
                            CR.pRead %= CR.MaxLength;
                        }
                        else
                        {
                            CR.pRead++;
                            CR.pRead %= CR.MaxLength;
                        }
                    }
                    else
                    {
                        CR.pRead++;
                        CR.pRead %= CR.MaxLength;
                    }

                } while ((((CR.pWrite + CR.MaxLength) - CR.pRead) % CR.MaxLength) >= CR.MinLen);
        }

        private void btn_EnableCAN_Click(object sender, EventArgs e)
        {
            byte[] BasicFunctionSet_Array = new byte[30];
            //case "5k":
            //    BFS.tBS1 = 4;
            //    BFS.tBS2 = 3;
            //    BFS.BRP = 719;
            //    break;
            //case "10k":
            //    BFS.tBS1 = 4;
            //    BFS.tBS2 = 3;
            //    BFS.BRP = 359;
            //    break;
            //case "20k":
            //    BFS.tBS1 = 4;
            //    BFS.tBS2 = 3;
            //    BFS.BRP = 179;
            //    break;
            //case "50k":
            //    BFS.tBS1 = 4;
            //    BFS.tBS2 = 3;
            //    BFS.BRP = 71;
            //    break;
            //case "100k":
            //    BFS.tBS1 = 4;
            //    BFS.tBS2 = 3;
            //    BFS.BRP = 35;
            //    break;
            //case "125k":
            //    BFS.tBS1 = 3;
            //    BFS.tBS2 = 3;
            //    BFS.BRP = 31;
            //    break;
            //case "200k":
            //    BFS.tBS1 = 4;
            //    BFS.tBS2 = 3;
            //    BFS.BRP = 17;
            //    break;
            //case "250k":
            //    BFS.tBS1 = 3;
            //    BFS.tBS2 = 3;
            //    BFS.BRP = 15;
            //    break;
            //case "400k":
            //    BFS.tBS1 = 4;
            //    BFS.tBS2 = 3;
            //    BFS.BRP = 8;
            //    break;
            //case "500k":
            //    BFS.tBS1 = 3;
            //    BFS.tBS2 = 3;
            //    BFS.BRP = 7;
            //    break;
            //case "600k":
            //    BFS.tBS1 = 4;
            //    BFS.tBS2 = 3;
            //    BFS.BRP = 5;
            //    break;
            //case "800k":
            //    BFS.tBS1 = 3;
            //    BFS.tBS2 = 3;
            //    BFS.BRP = 4;
            //    break;
            //case "1M":
            //    BFS.tBS1 = 3;
            //    BFS.tBS2 = 3;
            //    BFS.BRP = 3;
            //    break;

            BasicFunctionSet_Array[0] = 0x55; //报文头
            BasicFunctionSet_Array[1] = 0xAA;
            BasicFunctionSet_Array[2] = 0x01; // 功能码
            BasicFunctionSet_Array[3] = 0X00; // 正常模式
            BasicFunctionSet_Array[4] = 3;
            BasicFunctionSet_Array[5] = 3;
            BasicFunctionSet_Array[6] = 0;
            BasicFunctionSet_Array[7] = 7;
            BasicFunctionSet_Array[8] = 1;
            BasicFunctionSet_Array[28] = GetSumForCommand(BasicFunctionSet_Array);
            BasicFunctionSet_Array[29] = 0x88;

            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(BasicFunctionSet_Array, 0, 30);
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }



        public void LightStatusTest(byte[] dataBuf)   // 灯态解析程序
        {
            switch (dataBuf[4] + dataBuf[3])
            {
                case 64:    //2块
                    if (dataBuf[17] == 0x80)
                    {
                        lighttextBox8.AppendText("第1块板子灯态显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light01.BackColor = Color.FromArgb(255, 0, 0);
                        }

                        if (dataBuf[14] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light01.BackColor = Color.FromArgb(255, 255, 0);
                        }

                        if (dataBuf[14] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light01.BackColor = Color.FromArgb(0, 255, 0);
                        }

                        if (dataBuf[14] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light01.BackColor = Color.FromArgb(255, 255, 255);
                        }

                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light02.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[13] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light02.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[13] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light02.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[13] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light01.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light03.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[12] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light03.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[12] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light03.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[12] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light03.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light04.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[11] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light04.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[11] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //0, 255, 128
                            light04.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[11] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light04.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        lighttextBox8.AppendText("\r\n");
                    }
                    break;
                case 96:    //3块
                    if (dataBuf[17] == 0x80)
                    {
                        lighttextBox8.AppendText("第2块板子灯态显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light01.BackColor = Color.FromArgb(255, 0, 0);
                        }

                        if (dataBuf[14] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light01.BackColor = Color.FromArgb(255, 255, 0);
                        }

                        if (dataBuf[14] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light01.BackColor = Color.FromArgb(0, 255, 0);
                        }

                        if (dataBuf[14] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light01.BackColor = Color.FromArgb(255, 255, 255);
                        }

                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light02.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[13] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light02.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[13] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light02.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[13] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light01.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light03.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[12] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light03.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[12] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light03.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[12] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light03.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light04.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[11] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light04.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[11] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //0, 255, 128
                            light04.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[11] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light04.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        lighttextBox8.AppendText("\r\n");
                    }
                    break;
                case 128:   //4块
                    if (dataBuf[17] == 0x80)
                    {
                        lighttextBox8.AppendText("第3块板子灯态显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light01.BackColor = Color.FromArgb(255, 0, 0);
                        }

                        if (dataBuf[14] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light01.BackColor = Color.FromArgb(255, 255, 0);
                        }

                        if (dataBuf[14] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light01.BackColor = Color.FromArgb(0, 255, 0);
                        }

                        if (dataBuf[14] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light01.BackColor = Color.FromArgb(255, 255, 255);
                        }

                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light02.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[13] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light02.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[13] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light02.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[13] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light01.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light03.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[12] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light03.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[12] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light03.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[12] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light03.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light04.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[11] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light04.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[11] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //0, 255, 128
                            light04.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[11] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light04.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        lighttextBox8.AppendText("\r\n");
                    }
                    break;
                case 160:   //5块
                    if (dataBuf[17] == 0x80)
                    {
                        lighttextBox8.AppendText("第4块板子灯态显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light01.BackColor = Color.FromArgb(255, 0, 0);
                        }

                        if (dataBuf[14] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light01.BackColor = Color.FromArgb(255, 255, 0);
                        }

                        if (dataBuf[14] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light01.BackColor = Color.FromArgb(0, 255, 0);
                        }

                        if (dataBuf[14] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light01.BackColor = Color.FromArgb(255, 255, 255);
                        }

                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light02.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[13] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light02.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[13] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light02.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[13] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light01.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light03.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[12] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light03.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[12] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light03.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[12] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light03.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light04.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[11] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light04.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[11] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //0, 255, 128
                            light04.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[11] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light04.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        lighttextBox8.AppendText("\r\n");
                    }
                    break;
                case 192:   //6块
                    if (dataBuf[17] == 0x80)
                    {
                        lighttextBox8.AppendText("第5块板子灯态显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light01.BackColor = Color.FromArgb(255, 0, 0);
                        }

                        if (dataBuf[14] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light01.BackColor = Color.FromArgb(255, 255, 0);
                        }

                        if (dataBuf[14] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light01.BackColor = Color.FromArgb(0, 255, 0);
                        }

                        if (dataBuf[14] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light01.BackColor = Color.FromArgb(255, 255, 255);
                        }

                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light02.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[13] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light02.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[13] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light02.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[13] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light01.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light03.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[12] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light03.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[12] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light03.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[12] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light03.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light04.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[11] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light04.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[11] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //0, 255, 128
                            light04.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[11] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light04.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        lighttextBox8.AppendText("\r\n");
                    }
                    break;
                case 224:   //7块
                    if (dataBuf[17] == 0x80)
                    {
                        lighttextBox8.AppendText("第6块板子灯态显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light01.BackColor = Color.FromArgb(255, 0, 0);
                        }

                        if (dataBuf[14] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light01.BackColor = Color.FromArgb(255, 255, 0);
                        }

                        if (dataBuf[14] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light01.BackColor = Color.FromArgb(0, 255, 0);
                        }

                        if (dataBuf[14] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light01.BackColor = Color.FromArgb(255, 255, 255);
                        }

                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light02.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[13] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light02.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[13] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light02.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[13] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light01.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light03.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[12] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light03.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[12] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light03.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[12] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light03.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light04.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[11] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light04.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[11] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //0, 255, 128
                            light04.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[11] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light04.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        lighttextBox8.AppendText("\r\n");
                    }
                    break;
                case 1:     //8块   
                    if (dataBuf[17] == 0x80)
                    {
                        lighttextBox8.AppendText("第7块板子灯态显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light01.BackColor = Color.FromArgb(255, 0, 0);
                        }

                        if (dataBuf[14] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light01.BackColor = Color.FromArgb(255, 255, 0);
                        }

                        if (dataBuf[14] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light01.BackColor = Color.FromArgb(0, 255, 0);
                        }

                        if (dataBuf[14] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light01.BackColor = Color.FromArgb(255, 255, 255);
                        }

                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light02.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[13] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light02.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[13] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light02.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[13] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light01.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light03.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[12] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light03.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[12] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light03.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[12] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light03.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light04.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[11] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light04.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[11] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //0, 255, 128
                            light04.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[11] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light04.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        lighttextBox8.AppendText("\r\n");
                    }
                    break;
                case 33:   //9块
                    if (dataBuf[17] == 0x80)
                    {
                        lighttextBox8.AppendText("第8块板子灯态显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light01.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[14] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light01.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[14] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light01.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[14] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light01.BackColor = Color.FromArgb(255, 255, 255);
                        }

                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light02.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[13] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light02.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[13] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light02.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[13] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light01.BackColor = Color.FromArgb(255, 255, 255);
                        }

                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light03.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[12] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light03.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[12] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //128, 255, 128
                            light03.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[12] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light03.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x01)
                        {
                            lighttextBox8.AppendText("红灯 ");
                            light04.BackColor = Color.FromArgb(255, 0, 0);
                        }
                        if (dataBuf[11] == 0x02)
                        {
                            lighttextBox8.AppendText("黄灯 ");   //255, 255, 128
                            light04.BackColor = Color.FromArgb(255, 255, 0);
                        }
                        if (dataBuf[11] == 0x04)
                        {
                            lighttextBox8.AppendText("绿灯 ");   //0, 255, 128
                            light04.BackColor = Color.FromArgb(0, 255, 0);
                        }
                        if (dataBuf[11] == 0x00)
                        {
                            lighttextBox8.AppendText("无灯 ");
                            light04.BackColor = Color.FromArgb(255, 255, 255);
                        }
                        lighttextBox8.AppendText("\r\n");
                    }
                    break;
                default:
                    break;
            }
        }

        public void Light81Test(byte[] dataBuf) //81 亮故障检测
        {

            switch (dataBuf[4] + dataBuf[3])
            {
                case 64:    //2块
                    if (dataBuf[17] == 0x81)//
                    {
                        lighttextBox11.AppendText("第1块板子故障显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");

                        lighttextBox11.AppendText("\r\n");
                    }
                    break;
                case 96:    //3块
                    if (dataBuf[17] == 0x81)//
                    {
                        lighttextBox11.AppendText("第2块板子故障显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");

                        lighttextBox11.AppendText("\r\n");
                    }
                    break;
                case 128:   //4块
                    if (dataBuf[17] == 0x81)//
                    {
                        lighttextBox11.AppendText("第3块板子故障显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");

                        lighttextBox11.AppendText("\r\n");
                    }
                    break;
                case 160:   //5块
                    if (dataBuf[17] == 0x81)//
                    {
                        lighttextBox11.AppendText("第4块板子故障显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");

                        lighttextBox11.AppendText("\r\n");
                    }
                    break;
                case 192:   //6块
                    if (dataBuf[17] == 0x81)//
                    {
                        lighttextBox11.AppendText("第5块板子故障显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");

                        lighttextBox11.AppendText("\r\n");
                    }
                    break;
                case 224:   //7块
                    if (dataBuf[17] == 0x81)//
                    {
                        lighttextBox11.AppendText("第6块板子故障显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");

                        lighttextBox11.AppendText("\r\n");
                    }
                    break;
                case 1:     //8块   
                    if (dataBuf[17] == 0x81)//
                    {
                        lighttextBox11.AppendText("第7块板子故障显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");

                        lighttextBox11.AppendText("\r\n");
                    }
                    break;
                case 33:   //9块
                    if (dataBuf[17] == 0x81)//
                    {
                        lighttextBox11.AppendText("第8块板子故障显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox11.AppendText("正常 ");
                        else
                            lighttextBox11.AppendText("不亮 ");

                        lighttextBox11.AppendText("\r\n");
                    }
                    break;
                default:

                    break;
            }

        }
        public void Light82Test(byte[] dataBuf) //82 灭故障检测
        {

            switch (dataBuf[4] + dataBuf[3])
            {
                case 64:    //2块
                    if (dataBuf[17] == 0x82)//
                    {
                        lighttextBox12.AppendText("第1块板子故障显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");


                        lighttextBox12.AppendText("\r\n");
                    }
                    break;
                case 96:    //3块
                    if (dataBuf[17] == 0x82)//
                    {
                        lighttextBox12.AppendText("第2块板子故障显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");


                        lighttextBox12.AppendText("\r\n");
                    }
                    break;
                case 128:   //4块
                    if (dataBuf[17] == 0x82)//
                    {
                        lighttextBox12.AppendText("第3块板子故障显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");


                        lighttextBox12.AppendText("\r\n");
                    }
                    break;
                case 160:   //5块
                    if (dataBuf[17] == 0x82)//
                    {
                        lighttextBox12.AppendText("第4块板子故障显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");


                        lighttextBox12.AppendText("\r\n");
                    }
                    break;
                case 192:   //6块
                    if (dataBuf[17] == 0x82)//
                    {
                        lighttextBox12.AppendText("第5块板子故障显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");


                        lighttextBox12.AppendText("\r\n");
                    }
                    break;
                case 224:   //7块
                    if (dataBuf[17] == 0x82)//
                    {
                        lighttextBox12.AppendText("第6块板子故障显示: ");
                        //dataBuf[14]
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");

                        lighttextBox12.AppendText("\r\n");
                    }
                    break;
                case 1:     //8块   
                    if (dataBuf[17] == 0x82)//
                    {
                        lighttextBox12.AppendText("第7块板子故障显示: ");
                        //dataBuf[14]
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");


                        lighttextBox12.AppendText("\r\n");
                    }
                    break;
                case 33:   //9块
                    if (dataBuf[17] == 0x82)//
                    {
                        lighttextBox12.AppendText("第8块板子故障显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox12.AppendText("正常 ");
                        else
                            lighttextBox12.AppendText("不灭 ");

                        lighttextBox12.AppendText("\r\n");
                    }
                    break;
                default:

                    break;
            }

        }
        public void Light83Test(byte[] dataBuf) //83电流检测
        {
            switch (dataBuf[4] + dataBuf[3])
            {
                case 64:    //2块
                    if (dataBuf[17] == 0x83)//
                    {
                        lighttextBox9.AppendText("第1块板子电流显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");

                        lighttextBox9.AppendText("\r\n");
                    }
                    break;
                case 96:    //3块
                    if (dataBuf[17] == 0x83)//
                    {
                        lighttextBox9.AppendText("第2块板子电流显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");

                        lighttextBox9.AppendText("\r\n");
                    }
                    break;
                case 128:   //4块
                    if (dataBuf[17] == 0x83)//
                    {
                        lighttextBox9.AppendText("第3块板子电流显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");

                        lighttextBox9.AppendText("\r\n");
                    }
                    break;
                case 160:   //5块
                    if (dataBuf[17] == 0x83)//
                    {
                        lighttextBox9.AppendText("第4块板子电流显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");

                        lighttextBox9.AppendText("\r\n");
                    }
                    break;
                case 192:   //6块
                    if (dataBuf[17] == 0x83)//
                    {
                        lighttextBox9.AppendText("第5块板子电流显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");

                        lighttextBox9.AppendText("\r\n");
                    }
                    break;
                case 224:   //7块
                    if (dataBuf[17] == 0x83)//
                    {
                        lighttextBox9.AppendText("第6块板子电流显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");
                        lighttextBox9.AppendText("\r\n");
                    }
                    break;
                case 1:     //8块   
                    if (dataBuf[17] == 0x83)//
                    {
                        lighttextBox9.AppendText("第7块板子电流显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");

                        lighttextBox9.AppendText("\r\n");
                    }
                    break;
                case 33:   //9块
                    if (dataBuf[17] == 0x83)//
                    {
                        lighttextBox9.AppendText("第8块板子电流显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox9.AppendText("无电流 ");
                        else
                            lighttextBox9.AppendText("有电流 ");

                        lighttextBox9.AppendText("\r\n");
                    }
                    break;
                default:
                    //lighttextBox9.Text = " ";
                    break;
            }

        }

        public void Light84Test(byte[] dataBuf) //84电压监测
        {

            switch (dataBuf[4] + dataBuf[3])
            {
                case 64:    //2块
                    if (dataBuf[17] == 0x84)//
                    {
                        lighttextBox10.AppendText("第1块板子电压显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");

                        lighttextBox10.AppendText("\r\n");
                    }
                    break;
                case 96:    //3块
                    if (dataBuf[17] == 0x84)//
                    {
                        lighttextBox10.AppendText("第2块板子电压显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");

                        lighttextBox10.AppendText("\r\n");
                    }
                    break;
                case 128:   //4块
                    if (dataBuf[17] == 0x84)//
                    {
                        lighttextBox10.AppendText("第3块板子电压显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");

                        lighttextBox10.AppendText("\r\n");
                    }
                    break;
                case 160:   //5块
                    if (dataBuf[17] == 0x84)//
                    {
                        lighttextBox10.AppendText("第4块板子电压显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");

                        lighttextBox10.AppendText("\r\n");
                    }
                    break;
                case 192:   //6块
                    if (dataBuf[17] == 0x84)//
                    {
                        lighttextBox10.AppendText("第5块板子电压显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");

                        lighttextBox10.AppendText("\r\n");
                    }
                    break;
                case 224:   //7块
                    if (dataBuf[17] == 0x84)//
                    {
                        lighttextBox10.AppendText("第6块板子电压显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");

                        lighttextBox10.AppendText("\r\n");
                    }
                    break;
                case 1:     //8块   
                    if (dataBuf[17] == 0x84)//
                    {
                        lighttextBox10.AppendText("第7块板子电压显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");

                        lighttextBox10.AppendText("\r\n");
                    }
                    break;
                case 33:   //9块
                    if (dataBuf[17] == 0x84)//
                    {
                        lighttextBox10.AppendText("第8块板子电压显示: ");
                        //dataBuf[14]
                        if (dataBuf[14] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");
                        //dataBuf[13]                     
                        if (dataBuf[13] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");
                        //dataBuf[12]                     
                        if (dataBuf[12] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");

                        //dataBuf[11]                     
                        if (dataBuf[11] == 0x00)
                            lighttextBox10.AppendText("无电压 ");
                        else
                            lighttextBox10.AppendText("有电压 ");

                        lighttextBox10.AppendText("\r\n");
                    }
                    break;
                default:

                    break;
            }

        }

        #region 板一测试
        private void test1redbutton_Click(object sender, EventArgs e) //红灯
        {
            //清空面板
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";

            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //关闭其他状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            //开始测试
            byte[] startest = UtilHelper.no1Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no1RedTest();    //红灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no1Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

        }
        private void test1yelbutton_Click(object sender, EventArgs e)//黄灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no1Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no1YelTest();    //黄灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no1Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }
        private void test1button_Click(object sender, EventArgs e)//绿灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no1Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no1GreTest();    //绿灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no1Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }
        #endregion

        #region 板二测试
        private void test2redbutton_Click(object sender, EventArgs e)//红灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //滤波设置
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no2Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no2RedTest();    //红灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);

            //开启板1滤波
            byte[] no1Mask = UtilHelper.no2Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        private void test2yelbutton_Click(object sender, EventArgs e)//黄灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no2Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no2YelTest();    //黄灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no2Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        private void test2grebutton_Click(object sender, EventArgs e)//绿灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no2Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no2GreTest();    //绿灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no2Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }
        #endregion

        #region 板三测试
        private void test3redbutton_Click_1(object sender, EventArgs e)//红灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no3Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no3RedTest();    //红灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no3Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        private void test3yelbutton_Click_1(object sender, EventArgs e)//黄灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no3Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no3YelTest();    //黄灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no3Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        private void test3grebutton_Click_1(object sender, EventArgs e)//绿灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no3Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no3GreTest();    //绿灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no3Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        #endregion

        #region 板四测试
        private void test4redbutton_Click(object sender, EventArgs e)//红灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no4Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no4RedTest();    //红灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no4Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        private void test4yelbutton_Click(object sender, EventArgs e)//黄灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no4Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no4YelTest();    //黄灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no4Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        private void test4grebutton_Click(object sender, EventArgs e)//绿灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no4Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no4GreTest();    //绿灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no4Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }
        #endregion

        #region 板五测试
        private void test5redbutton_Click(object sender, EventArgs e)//红灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no5Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no5RedTest();    //红灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no5Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        private void test5yelbutton_Click(object sender, EventArgs e)//黄灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no5Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no5YelTest();    //黄灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no5Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        private void test5grebutton_Click(object sender, EventArgs e)//绿灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no5Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no5GreTest();    //绿灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no5Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        #endregion

        #region 板6测试
        private void test6redbutton_Click(object sender, EventArgs e)//红灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no6Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no6RedTest();    //红灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no6Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        private void test6yelbutton_Click(object sender, EventArgs e)//黄灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no6Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no6YelTest();    //黄灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no6Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        private void test6grebutton_Click(object sender, EventArgs e)//绿灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no6Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no6GreTest();    //绿灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no6Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        #endregion
        #region 板7测试
        private void test7redbutton_Click(object sender, EventArgs e)//红灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no7Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no7RedTest();    //红灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no7Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        private void test7yelbutton_Click(object sender, EventArgs e)//黄灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no7Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no7YelTest();    //黄灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no7Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        private void test7grebutton_Click(object sender, EventArgs e)//绿灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no7Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no7GreTest();    //绿灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no7Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        #endregion
        #region 板8测试
        private void test8redbutton_Click(object sender, EventArgs e)//红灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no8Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no8RedTest();    //红灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no8Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        private void test8yelbutton_Click(object sender, EventArgs e)//黄灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no8Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no8YelTest();    //黄灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no8Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        private void test8grebutton_Click(object sender, EventArgs e)//绿灯
        {
            light01.BackColor = Color.FromArgb(255, 255, 255);
            light02.BackColor = Color.FromArgb(255, 255, 255);
            light03.BackColor = Color.FromArgb(255, 255, 255);
            light04.BackColor = Color.FromArgb(255, 255, 255);
            lighttextBox8.Text = " ";
            lighttextBox9.Text = " ";
            lighttextBox10.Text = " ";
            lighttextBox11.Text = " ";
            lighttextBox12.Text = " ";
            //设置滤波
            //先关闭其他滤波
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }

            byte[] startest = UtilHelper.no8Test(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(startest, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in startest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //Thread.Sleep(2000);
            byte[] redtest = UtilHelper.no8GreTest();    //绿灯控制
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(redtest, 0, 30);
                    //发送显示
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");
                    foreach (byte i in redtest)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());
                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
            //睡眠1秒，给机器反应时间
            Thread.Sleep(sleepTime);
            //开启板1滤波
            byte[] no1Mask = UtilHelper.no8Mask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(no1Mask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in no1Mask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        #endregion

        private void teststop_Click(object sender, EventArgs e)
        {
            MessageBox.Show("已停止测试!!", "提示");
        }



        #region 分析程序
        public void LightStatusAnay(byte[] dataBuf)   // 灯态解析程序 红4，黄6，绿18
        {

            switch (dataBuf[4] + dataBuf[3])
            {
                case 64:    //2块
                    if (dataBuf[17] == 0x80)//灯态分析 5
                    {
                        //if(dataBuf[11]+ dataBuf[12]+ dataBuf[13]+ dataBuf[14] != 4&& dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14] != 6&& dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14] != 18)
                        if ((dataBuf[14] == 1 && dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1) || (dataBuf[14] == 2 && dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0) || (dataBuf[14] == 4 && dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4))
                        {//正常
                         //dataBuf[14]==1&& dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1 红灯正常
                         //dataBuf[14]==2&& dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0 黄灯正常
                         //dataBuf[14]==4&& dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4 绿灯正常
                         // var xx = dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14];
                         //MessageBox.Show("提示：灯态正常常" + xx, "提示");
                        }
                        else
                        {
                            //发送停止接收命令
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板1：灯态异常" + msg, "提示");

                        }

                    }
                    if (dataBuf[17] == 0x81 || dataBuf[17] == 0x82)//故障分析
                    {
                        if (dataBuf[17] == 0x81)
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板1：灯亮故障" + msg, "提示");
                        }
                        if (dataBuf[17] == 0x82)
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板1：灯灭故障" + msg, "提示");
                        }

                    }
                    if (dataBuf[17] == 0x83 || dataBuf[17] == 0x84)//电流 电压分析
                    {
                        if ((dataBuf[14] == 1 && dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1) || (dataBuf[14] == 2 && dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0) || (dataBuf[14] == 4 && dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4))
                        {//正常
                         //dataBuf[14]==1&& dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1 红灯正常
                         //dataBuf[14]==2&& dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0 黄灯正常
                         //dataBuf[14]==4&& dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4 绿灯正常
                         // var xx = dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14];
                         //   MessageBox.Show("提示：电流电压正常", "提示");
                        }
                        else
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板1：电流电压异常" + msg, "提示");
                        }
                    }
                    break;
                case 96:    //3块
                    if (dataBuf[17] == 0x80)//灯态分析 5
                    {
                        //if(dataBuf[11]+ dataBuf[12]+ dataBuf[13]+ dataBuf[14] != 4&& dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14] != 6&& dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14] != 18)
                        if ((dataBuf[14] == 1 && dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1) || (dataBuf[14] == 2 && dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0) || (dataBuf[14] == 4 && dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4))
                        {//正常
                         //dataBuf[14]==1&& dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1 红灯正常
                         //dataBuf[14]==2&& dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0 黄灯正常
                         //dataBuf[14]==4&& dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4 绿灯正常
                         // var xx = dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14];
                         //MessageBox.Show("提示：灯态正常常" + xx, "提示");
                        }
                        else
                        {
                            //发送停止接收命令
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板2：灯态异常" + msg, "提示");

                        }

                    }
                    if (dataBuf[17] == 0x81 || dataBuf[17] == 0x82)//故障分析
                    {
                        if (dataBuf[17] == 0x81)
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板2：灯亮故障" + msg, "提示");
                        }
                        if (dataBuf[17] == 0x82)
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误xxx：灯灭故障" + msg, "提示");
                        }

                    }
                    if (dataBuf[17] == 0x83 || dataBuf[17] == 0x84)//电流 电压分析
                    {
                        if ((dataBuf[14] == 1 && dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1) || (dataBuf[14] == 2 && dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0) || (dataBuf[14] == 4 && dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4))
                        {//正常
                         //dataBuf[14]==1&& dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1 红灯正常
                         //dataBuf[14]==2&& dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0 黄灯正常
                         //dataBuf[14]==4&& dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4 绿灯正常
                         // var xx = dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14];
                         //  MessageBox.Show("提示：电流电压正常", "提示");
                        }
                        else
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板2：电流电压异常" + msg, "提示");
                        }
                    }
                    break;
                case 128:   //4块
                    if (dataBuf[17] == 0x80)//灯态分析 5
                    {
                        //if(dataBuf[11]+ dataBuf[12]+ dataBuf[13]+ dataBuf[14] != 4&& dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14] != 6&& dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14] != 18)
                        if ((dataBuf[14] == 1 && dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1) || (dataBuf[14] == 2 && dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0) || (dataBuf[14] == 4 && dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4))
                        {//正常
                         //dataBuf[14]==1&& dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1 红灯正常
                         //dataBuf[14]==2&& dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0 黄灯正常
                         //dataBuf[14]==4&& dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4 绿灯正常
                         // var xx = dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14];
                         //MessageBox.Show("提示：灯态正常常" + xx, "提示");
                        }
                        else
                        {
                            //发送停止接收命令
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板3：灯态异常" + msg, "提示");

                        }

                    }
                    if (dataBuf[17] == 0x81 || dataBuf[17] == 0x82)//故障分析
                    {
                        if (dataBuf[17] == 0x81)
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板3：灯亮故障" + msg, "提示");
                        }
                        if (dataBuf[17] == 0x82)
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板3：灯灭故障" + msg, "提示");
                        }

                    }
                    if (dataBuf[17] == 0x83 || dataBuf[17] == 0x84)//电流 电压分析
                    {
                        if ((dataBuf[14] == 1 && dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1) || (dataBuf[14] == 2 && dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0) || (dataBuf[14] == 4 && dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4))
                        {//正常
                         //dataBuf[14]==1&& dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1 红灯正常
                         //dataBuf[14]==2&& dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0 黄灯正常
                         //dataBuf[14]==4&& dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4 绿灯正常
                         // var xx = dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14];
                         // MessageBox.Show("提示：电流电压正常", "提示");
                        }
                        else
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板3：电流电压异常" + msg, "提示");
                        }
                    }
                    break;
                case 160:   //5块
                    if (dataBuf[17] == 0x80)//灯态分析 5
                    {
                        //if(dataBuf[11]+ dataBuf[12]+ dataBuf[13]+ dataBuf[14] != 4&& dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14] != 6&& dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14] != 18)
                        if ((dataBuf[14] == 1 && dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1) || (dataBuf[14] == 2 && dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0) || (dataBuf[14] == 4 && dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4))
                        {//正常
                         //dataBuf[14]==1&& dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1 红灯正常
                         //dataBuf[14]==2&& dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0 黄灯正常
                         //dataBuf[14]==4&& dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4 绿灯正常
                         // var xx = dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14];
                         //MessageBox.Show("提示：灯态正常常" + xx, "提示");
                        }
                        else
                        {
                            //发送停止接收命令
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板4：灯态异常" + msg, "提示");

                        }

                    }
                    if (dataBuf[17] == 0x81 || dataBuf[17] == 0x82)//故障分析
                    {
                        if (dataBuf[17] == 0x81)
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板4：灯亮故障" + msg, "提示");
                        }
                        if (dataBuf[17] == 0x82)
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误xxx：灯灭故障" + msg, "提示");
                        }

                    }
                    if (dataBuf[17] == 0x83 || dataBuf[17] == 0x84)//电流 电压分析
                    {
                        if ((dataBuf[14] == 1 && dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1) || (dataBuf[14] == 2 && dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0) || (dataBuf[14] == 4 && dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4))
                        {//正常
                         //dataBuf[14]==1&& dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1 红灯正常
                         //dataBuf[14]==2&& dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0 黄灯正常
                         //dataBuf[14]==4&& dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4 绿灯正常
                         // var xx = dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14];
                         // MessageBox.Show("提示：电流电压正常", "提示");
                        }
                        else
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板4：电流电压异常" + msg, "提示");
                        }
                    }
                    break;
                case 192:   //6块
                    if (dataBuf[17] == 0x80)//灯态分析 5
                    {
                        //if(dataBuf[11]+ dataBuf[12]+ dataBuf[13]+ dataBuf[14] != 4&& dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14] != 6&& dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14] != 18)
                        if ((dataBuf[14] == 1 && dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1) || (dataBuf[14] == 2 && dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0) || (dataBuf[14] == 4 && dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4))
                        {//正常
                         //dataBuf[14]==1&& dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1 红灯正常
                         //dataBuf[14]==2&& dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0 黄灯正常
                         //dataBuf[14]==4&& dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4 绿灯正常
                         // var xx = dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14];
                         //MessageBox.Show("提示：灯态正常常" + xx, "提示");
                        }
                        else
                        {
                            //发送停止接收命令
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板5：灯态异常" + msg, "提示");

                        }

                    }
                    if (dataBuf[17] == 0x81 || dataBuf[17] == 0x82)//故障分析
                    {
                        if (dataBuf[17] == 0x81)
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板5：灯亮故障" + msg, "提示");
                        }
                        if (dataBuf[17] == 0x82)
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板5：灯灭故障" + msg, "提示");
                        }

                    }
                    if (dataBuf[17] == 0x83 || dataBuf[17] == 0x84)//电流 电压分析
                    {
                        if ((dataBuf[14] == 1 && dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1) || (dataBuf[14] == 2 && dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0) || (dataBuf[14] == 4 && dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4))
                        {//正常
                         //dataBuf[14]==1&& dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1 红灯正常
                         //dataBuf[14]==2&& dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0 黄灯正常
                         //dataBuf[14]==4&& dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4 绿灯正常
                         // var xx = dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14];
                         //MessageBox.Show("提示：电流电压正常" , "提示");
                        }
                        else
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板5：电流电压异常" + msg, "提示");
                        }
                    }
                    break;
                case 224:   //7块
                    if (dataBuf[17] == 0x80)//灯态分析 5
                    {
                        //if(dataBuf[11]+ dataBuf[12]+ dataBuf[13]+ dataBuf[14] != 4&& dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14] != 6&& dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14] != 18)
                        if ((dataBuf[14] == 1 && dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1) || (dataBuf[14] == 2 && dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0) || (dataBuf[14] == 4 && dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4))
                        {//正常
                         //dataBuf[14]==1&& dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1 红灯正常
                         //dataBuf[14]==2&& dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0 黄灯正常
                         //dataBuf[14]==4&& dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4 绿灯正常
                         // var xx = dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14];
                         //MessageBox.Show("提示：灯态正常常" + xx, "提示");
                        }
                        else
                        {
                            //发送停止接收命令
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板6：灯态异常" + msg, "提示");

                        }

                    }
                    if (dataBuf[17] == 0x81 || dataBuf[17] == 0x82)//故障分析
                    {
                        if (dataBuf[17] == 0x81)
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板6：灯亮故障" + msg, "提示");
                        }
                        if (dataBuf[17] == 0x82)
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板6：灯灭故障" + msg, "提示");
                        }

                    }
                    if (dataBuf[17] == 0x83 || dataBuf[17] == 0x84)//电流 电压分析
                    {
                        if ((dataBuf[14] == 1 && dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1) || (dataBuf[14] == 2 && dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0) || (dataBuf[14] == 4 && dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4))
                        {//正常
                         //dataBuf[14]==1&& dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1 红灯正常
                         //dataBuf[14]==2&& dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0 黄灯正常
                         //dataBuf[14]==4&& dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4 绿灯正常
                         // var xx = dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14];
                         //MessageBox.Show("提示：电流电压正常", "提示");
                        }
                        else
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板6：电流电压异常" + msg, "提示");
                        }
                    }
                    break;
                case 1:     //8块   
                    if (dataBuf[17] == 0x80)//灯态分析 5
                    {
                        //if(dataBuf[11]+ dataBuf[12]+ dataBuf[13]+ dataBuf[14] != 4&& dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14] != 6&& dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14] != 18)
                        if ((dataBuf[14] == 1 && dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1) || (dataBuf[14] == 2 && dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0) || (dataBuf[14] == 4 && dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4))
                        {//正常
                         //dataBuf[14]==1&& dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1 红灯正常
                         //dataBuf[14]==2&& dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0 黄灯正常
                         //dataBuf[14]==4&& dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4 绿灯正常
                         // var xx = dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14];
                         //MessageBox.Show("提示：灯态正常常" + xx, "提示");
                        }
                        else
                        {
                            //发送停止接收命令
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板7：灯态异常" + msg, "提示");

                        }

                    }
                    if (dataBuf[17] == 0x81 || dataBuf[17] == 0x82)//故障分析
                    {
                        if (dataBuf[17] == 0x81)
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板7：灯亮故障" + msg, "提示");
                        }
                        if (dataBuf[17] == 0x82)
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板7：灯灭故障" + msg, "提示");
                        }

                    }
                    if (dataBuf[17] == 0x83 || dataBuf[17] == 0x84)//电流 电压分析
                    {
                        if ((dataBuf[14] == 1 && dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1) || (dataBuf[14] == 2 && dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0) || (dataBuf[14] == 4 && dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4))
                        {//正常
                         //dataBuf[14]==1&& dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1 红灯正常
                         //dataBuf[14]==2&& dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0 黄灯正常
                         //dataBuf[14]==4&& dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4 绿灯正常
                         // var xx = dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14];
                         //  MessageBox.Show("提示：电流电压正常", "提示");
                        }
                        else
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板7：电流电压异常" + msg, "提示");
                        }
                    }
                    break;
                case 33:   //9块
                    if (dataBuf[17] == 0x80)//灯态分析 5
                    {
                        //if(dataBuf[11]+ dataBuf[12]+ dataBuf[13]+ dataBuf[14] != 4&& dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14] != 6&& dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14] != 18)
                        if ((dataBuf[14] == 1 && dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1) || (dataBuf[14] == 2 && dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0) || (dataBuf[14] == 4 && dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4))
                        {//正常
                         //dataBuf[14]==1&& dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1 红灯正常
                         //dataBuf[14]==2&& dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0 黄灯正常
                         //dataBuf[14]==4&& dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4 绿灯正常
                         // var xx = dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14];
                         //MessageBox.Show("提示：灯态正常常" + xx, "提示");
                        }
                        else
                        {
                            //发送停止接收命令
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板8：灯态异常" + msg, "提示");

                        }

                    }
                    if (dataBuf[17] == 0x81 || dataBuf[17] == 0x82)//故障分析
                    {
                        if (dataBuf[17] == 0x81)
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板8：灯亮故障" + msg, "提示");
                        }
                        if (dataBuf[17] == 0x82)
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板8：灯灭故障" + msg, "提示");
                        }

                    }
                    if (dataBuf[17] == 0x83 || dataBuf[17] == 0x84)//电流 电压分析
                    {
                        if ((dataBuf[14] == 1 && dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1) || (dataBuf[14] == 2 && dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0) || (dataBuf[14] == 4 && dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4))
                        {//正常
                         //dataBuf[14]==1&& dataBuf[13] == 1 && dataBuf[12] == 1 && dataBuf[11] == 1 红灯正常
                         //dataBuf[14]==2&& dataBuf[13] == 2 && dataBuf[12] == 2 && dataBuf[11] == 0 黄灯正常
                         //dataBuf[14]==4&& dataBuf[13] == 4 && dataBuf[12] == 4 && dataBuf[11] == 4 绿灯正常
                         // var xx = dataBuf[11] + dataBuf[12] + dataBuf[13] + dataBuf[14];
                         //  MessageBox.Show("提示：电流电压正常", "提示");
                        }
                        else
                        {
                            StringBuilder msg = new StringBuilder();
                            msg.Append(Convert.ToString(dataBuf[17], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[14], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[13], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[12], 16));
                            msg.Append(" ");
                            msg.Append(Convert.ToString(dataBuf[11], 16));
                            closeAllMask();
                            MessageBox.Show("错误板8：电流电压异常" + msg, "提示");
                        }
                    }
                    break;
                default:
                    break;
            }
        }
        #endregion

        public void closeAllMask()//关闭所有滤波
        {
            byte[] closeMask = UtilHelper.CloseAllMask(); //测试状态
            switch (serialPort1.IsOpen)
            {
                case true:
                    serialPort1.Write(closeMask, 0, 30);
                    StringBuilder sb = new StringBuilder();
                    sb.Insert(sb.Length, "发送数据：");

                    //发送显示
                    foreach (byte i in closeMask)
                    {
                        sb.Insert(sb.Length, Convert.ToString(i, 16));
                        sb.Insert(sb.Length, " ");
                    }
                    sb.Insert(sb.Length, "\n");
                    textBox2.AppendText(sb.ToString());

                    break;
                case false:
                    MessageBox.Show("错误xxx：串口没有打开，请检查", "提示");
                    break;
                default: break;
            }
        }

        #region 定时任务
        private void testall_Click(object sender, EventArgs e)//开始自动测试
        {
            //开启定时任务
            if (timer11.Enabled == true)
            {
                timer11.Enabled = false;
                signNum = 0;//标记初始化
                autotest.Text = "开始自动测试";
                autotest.BackColor = Color.FromArgb(192, 255, 192);
                MessageBox.Show("已关闭自动测试!!","提示");
            }
            else
            {
                timer11.Enabled = true;
                autotest.Text = "关闭自动测试";
                autotest.BackColor = Color.FromArgb(255, 192, 192);
                MessageBox.Show("已开启自动测试!!", "提示");
            }
        }
        private void timer1_Tick(object sender, EventArgs e)//定时器
        {
            #region 板一
            if (signNum >= 0 && signNum < 1)//0为1板测试
            {
                // textBox1.Text = ("1");
                test1redbutton_Click(sender, e);
                textBox1.Text = ("1");
            }
            if (signNum >= 1 && signNum < 2)//1,2
            {
                test1yelbutton_Click(sender, e);

            }
            if (signNum >= 2 && signNum < 3)//2,3
            {
                test1button_Click(sender, e);
                textBox1.Text = ("3");
            }
            #endregion
            #region 板二
            if (signNum >= 3 && signNum < 4)//板二测试
            {
                test2redbutton_Click(sender, e);
                textBox1.Text = ("4");
            }
            if (signNum >= 4 && signNum < 5)//5
            {
                test2yelbutton_Click(sender, e);
                textBox1.Text = ("5");
            }
            if (signNum >= 5 && signNum < 6)//6
            {
                test2grebutton_Click(sender, e);
                textBox1.Text = ("6");
            }
            #endregion
            #region 板三
            if (signNum >= 6 && signNum < 7)//板三测试
            {
                test3redbutton_Click_1(sender, e);
                textBox1.Text = ("7");
            }
            if (signNum >= 7 && signNum < 8)//
            {
                test3yelbutton_Click_1(sender, e);
                textBox1.Text = ("8");
            }
            if (signNum >= 8 && signNum < 9)//
            {
                test3grebutton_Click_1(sender, e);
                textBox1.Text = ("8");
            }
            #endregion
            #region 板四
            if (signNum >= 9 && signNum < 10)//板四测试
            {
                test4redbutton_Click(sender, e);
                textBox1.Text = ("8");
            }
            if (signNum >= 10 && signNum < 11)//板四测试
            {
                test4yelbutton_Click(sender, e);
                textBox1.Text = ("8");
            }
            if (signNum >= 11 && signNum < 12)//板四测试
            {
                test4grebutton_Click(sender, e);
                textBox1.Text = ("8");
            }
            #endregion
            #region 板五
            if (signNum >= 12 && signNum < 13)//板五测试
            {
                test5redbutton_Click(sender, e);
                textBox1.Text = ("8");
            }
            if (signNum >= 13 && signNum < 14)//板五测试
            {
                test5yelbutton_Click(sender, e);
                textBox1.Text = ("8");
            }
            if (signNum >= 14 && signNum < 15)//板五测试
            {
                test5grebutton_Click(sender, e);
                textBox1.Text = ("8");
            }
            #endregion
            #region 板6
            if (signNum >= 15 && signNum < 16)//板六测试
            {
                test6redbutton_Click(sender, e);
                textBox1.Text = ("8");
            }
            if (signNum >= 16 && signNum < 17)//板六测试
            {
                test6yelbutton_Click(sender, e);
                textBox1.Text = ("8");
            }
            if (signNum >= 17 && signNum < 18)//板六测试
            {
                test6grebutton_Click(sender, e);
                textBox1.Text = ("8");
            }
            #endregion
            #region 板7
            if (signNum >= 18 && signNum < 19)//板七测试
            {
                test7redbutton_Click(sender, e);
                textBox1.Text = ("8");
            }
            if (signNum >= 19 && signNum < 20)//板七测试
            {
                test7yelbutton_Click(sender, e);
                textBox1.Text = ("8");
            }
            if (signNum >= 20 && signNum < 21)//板七测试
            {
                test7grebutton_Click(sender, e);
                textBox1.Text = ("8");
            }
            #endregion
            #region 板8
            if (signNum >= 21 && signNum < 22)//板八测试
            {
                test8redbutton_Click(sender, e);
                textBox1.Text = ("8");
            }
            if (signNum >= 22 && signNum < 23)//板8测试
            {
                test8yelbutton_Click(sender, e);
                textBox1.Text = ("8");
            }
            if (signNum >= 23 && signNum < 24)//板8测试
            {
                test8grebutton_Click(sender, e);
                textBox1.Text = ("8");
            }
            #endregion
            //循环结束
            if (signNum >= 24)
            {
                timer11.Enabled = false;
                signNum = 0;
                MessageBox.Show("自动测试结束");
                autotest.Text = "开启定时器";
            }
            signNum++;
        }
        #endregion

    }
}
